/**
 * @author LKQ
 * @date 2021/11/30 21:04
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.strStr("aa", "aa"));
    }
    public int strStr(String haystack, String needle) {
        int h1 = haystack.length(), n1 = needle.length();
        if ("".equals(needle)) {
            return 0;
        }
        if (h1 < n1 || "".equals(haystack)) {
            return -1;
        }
        int fast = 0;
        while (fast < h1 ) {
            String temp = fast < (h1-n1) ?  haystack.substring(fast, fast+ n1) : haystack.substring(fast);
            if (!needle.equals(temp)) {
                fast++;
            }else {
                break;
            }
        }
        if (fast == h1) {
            // 一直无法匹配
            return -1;
        }
        return fast;
    }
}
